﻿using NHibernate;

namespace ELearningSystem.Gateway.Gateway
{
    public class CommonGateway
    {
        public ISessionFactory createDataBaseSession = DatabaseConfigure.CreateDbSessionFactory();
       public bool Delete(object entity)
        {
            using (ISession session = createDataBaseSession.OpenSession())
            {

                using (ITransaction transaction = session.BeginTransaction())
                {
                    session.Delete(entity);
                    transaction.Commit();
                    return true;
                }
            }
        }

        public bool SaveOrUpdate(object entity)
        {
            using (ISession session = createDataBaseSession.OpenSession())
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    session.SaveOrUpdate(entity);
                    transaction.Commit();
                    session.Close();
                    return true;
                }
                
            }
        }
    }
}
